<template>
  <div>
    <div>&nbsp;</div>
    <div>&nbsp;</div>
    <h1>{{ 'Test Rpc' }}</h1>

    <div>&nbsp;</div>
    <button @click="onclick"><H1>Connect</H1></button>

    <h2>-- result---</h2>
    {{ result }}
    <h2>-- result.server_version---</h2>
    {{ result.server_version }}

    <div>&nbsp;</div>
    <button @click="onclickLogin"><H1>Login</H1></button>

    <h2>--error.code---</h2>
    {{ error.code }}

    <h2>--error.message---</h2>
    {{ error.message }}

    <h2>--error.data.name---</h2>
    {{ error.data.name }}

    <h2>--error.data.message---</h2>
    {{ error.data.message }}

    <h2>--error.data.debug---</h2>

    <div style="white-space: pre">
      {{ error.data.debug }}
    </div>

    <div>&nbsp;</div>
    <button @click="onclickHttp"><H1>Http Request</H1></button>
    <h2>-- http: http_data---</h2>
    {{ http_data }}

    <div>&nbsp;</div>
    <div>&nbsp;</div>
  </div>
</template>

<script>
import api from '@/api_demo/odoorpc_t3'

// const baseURL = 'http://192.168.56.108:8069'
const baseURL = process.env.VUE_APP_BASE_API
const timeout = 50000
api.init({ baseURL, timeout })

export default {
  name: 'TestRpc',
  props: {},
  data() {
    return {
      response: {},
      config: {},
      data: {},
      result: {},
      error: { data: {} },

      http_data: ''
    }
  },
  computed: {},

  async created() {},
  methods: {
    async onclick() {
      console.log('click btn')
      const result = await api.web.webclient.version_info()
      console.log('result:', result)
      this.result = result
      this.error = { data: {} }
    },

    async onclickLogin() {
      console.log('click btn')

      try {
        const kwargs = { db: 't1', login: 'admin', password: '123456' }
        const result = await api.web.session.authenticate(kwargs)
        console.log('result:', result)
        this.result = result
      } catch (error) {
        console.log('error:', error)
        this.error = error
        this.result = {}
      }
    },

    async onclickHttp() {
      const http_data = await api.web.tests_mobile()
      console.log('http_data:', http_data)
      this.http_data = http_data
    }
  }
}
</script>

<style scoped></style>
